package cmd

import (
	"context"
	"time"

	"device-admin/config/redis"
	"device-admin/internal/define"

	"github.com/spf13/cobra"
)

func init() {
	rootCmd.AddCommand(restartCmd)
}

var restartCmd = &cobra.Command{
	Use:   "restart",
	Short: "restart",
	Run: func(cmd *cobra.Command, args []string) {
		ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
		defer cancel()
		rdb := redis.NewDB()
		// 用于生产
		_, err := rdb.Set(ctx, define.RedisAppVersion, define.APPVersion, 0).Result()
		if err != nil {
			panic("重启失败")
		}
	},
}
